/*
 *  xinttypes.h
 *  (for Visual C++)
 *
 *  Copyright (C) 2008 by Kijineko Inc.
 *  Copyright (C) 2008 by TAKAGI Nobuhisa
 */
#pragma once

#ifndef _WIN32
#error  only win32 target supported!
#endif

#ifdef  _UNICODE
# define  __T(x)  L ## x
#else
# define  __T(x)  x
#endif

#define PRId16      __T("hd")
#define PRId32      __T("I32d")
#define PRId64      __T("I64d")
#define PRIdLEAST16 __T("hd")
#define PRIdLEAST32 __T("I32d")
#define PRIdLEAST64 __T("I64d")
#define PRIdFAST16  __T("hd")
#define PRIdFAST32  __T("I32d")
#define PRIdFAST64  __T("I64d")
#define PRIdPTR     __T("Id")

#define PRIi16      __T("hi")
#define PRIi32      __T("I32i")
#define PRIi64      __T("I64i")
#define PRIiLEAST16 __T("hi")
#define PRIiLEAST32 __T("I32i")
#define PRIiLEAST64 __T("I64i")
#define PRIiFAST16  __T("hi")
#define PRIiFAST32  __T("I32i")
#define PRIiFAST64  __T("I64i")
#define PRIiPTR     __T("Ii")

#define PRIu16      __T("hu")
#define PRIu32      __T("I32u")
#define PRIu64      __T("I64u")
#define PRIuLEAST16 __T("hu")
#define PRIuLEAST32 __T("I32u")
#define PRIuLEAST64 __T("I64u")
#define PRIuFAST16  __T("hu")
#define PRIuFAST32  __T("I32u")
#define PRIuFAST64  __T("I64u")
#define PRIuPTR     __T("Iu")

#define PRIx16      __T("hx")
#define PRIx32      __T("I32x")
#define PRIx64      __T("I64x")
#define PRIxLEAST16 __T("hx")
#define PRIxLEAST32 __T("I32x")
#define PRIxLEAST64 __T("I64x")
#define PRIxFAST16  __T("hx")
#define PRIxFAST32  __T("I32x")
#define PRIxFAST64  __T("I64x")
#define PRIxPTR     __T("Ix")

#define PRIX16      __T("hX")
#define PRIX32      __T("I32X")
#define PRIX64      __T("I64X")
#define PRIXLEAST16 __T("hX")
#define PRIXLEAST32 __T("I32X")
#define PRIXLEAST64 __T("I64X")
#define PRIXFAST16  __T("hX")
#define PRIXFAST32  __T("I32X")
#define PRIXFAST64  __T("I64X")
#define PRIXPTR     __T("IX")

#define PRIo16      __T("ho")
#define PRIo32      __T("I32o")
#define PRIo64      __T("I64o")
#define PRIoLEAST16 __T("ho")
#define PRIoLEAST32 __T("I32o")
#define PRIoLEAST64 __T("I64o")
#define PRIoFAST16  __T("ho")
#define PRIoFAST32  __T("I32o")
#define PRIoFAST64  __T("I64o")
#define PRIoPTR     __T("Io")

#define SCNd16      __T("hd")
#define SCNd32      __T("I32d")
#define SCNd64      __T("I64d")
#define SCNdLEAST16 __T("hd")
#define SCNdLEAST32 __T("I32d")
#define SCNdLEAST64 __T("I64d")
#define SCNdFAST16  __T("hd")
#define SCNdFAST32  __T("I32d")
#define SCNdFAST64  __T("I64d")
#define SCNdPTR     __T("Id")

#define SCNi16      __T("hi")
#define SCNi32      __T("I32i")
#define SCNi64      __T("I64i")
#define SCNiLEAST16 __T("hi")
#define SCNiLEAST32 __T("I32i")
#define SCNiLEAST64 __T("I64i")
#define SCNiFAST16  __T("hi")
#define SCNiFAST32  __T("I32i")
#define SCNiFAST64  __T("I64i")
#define SCNiPTR     __T("Ii")

#define SCNu16      __T("hu")
#define SCNu32      __T("I32u")
#define SCNu64      __T("I64u")
#define SCNuLEAST16 __T("hu")
#define SCNuLEAST32 __T("I32u")
#define SCNuLEAST64 __T("I64u")
#define SCNuFAST16  __T("hu")
#define SCNuFAST32  __T("I32u")
#define SCNuFAST64  __T("I64u")
#define SCNuPTR     __T("Iu")

#define SCNx16      __T("hx")
#define SCNx32      __T("I32x")
#define SCNx64      __T("I64x")
#define SCNxLEAST16 __T("hx")
#define SCNxLEAST32 __T("I32x")
#define SCNxLEAST64 __T("I64x")
#define SCNxFAST16  __T("hx")
#define SCNxFAST32  __T("I32x")
#define SCNxFAST64  __T("I64x")
#define SCNxPTR     __T("Ix")

#define SCNo16      __T("ho")
#define SCNo32      __T("I32o")
#define SCNo64      __T("I64o")
#define SCNoLEAST16 __T("ho")
#define SCNoLEAST32 __T("I32o")
#define SCNoLEAST64 __T("I64o")
#define SCNoFAST16  __T("ho")
#define SCNoFAST32  __T("I32o")
#define SCNoFAST64  __T("I64o")
#define SCNoPTR     __T("Io")

#if _INTEGRAL_MAX_BITS == 64

#define PRIdMAX   __T("I64d")
#define PRIiMAX   __T("I64i")
#define PRIuMAX   __T("I64u")
#define PRIxMAX   __T("I64x")
#define PRIXMAX   __T("I64X")
#define PRIoMAX   __T("I64o")

#define SCNdMAX   __T("I64d")
#define SCNiMAX   __T("I64i")
#define SCNuMAX   __T("I64u")
#define SCNxMAX   __T("I64x")
#define SCNoMAX   __T("I64o")

#endif  /* _INTEGRAL_MAX_BITS == 64 */

#ifdef  __cplusplus
namespace std { namespace tr1 { extern "C" {
#endif

typedef struct _imaxdiv_t
{
	intmax_t quot;
	intmax_t rem;
} imaxdiv_t;


__inline intmax_t imaxabs(intmax_t __j)
{
	return __j < 0 ? -__j : __j;
}

__inline imaxdiv_t imaxdiv(intmax_t __numer, intmax_t __denom)
{
	imaxdiv_t __r;
	__r.quot = __numer / __denom;
	__r.rem	 = __numer % __denom;
	return __r;
}

intmax_t __cdecl strtoimax(const char*, char**, int);
uintmax_t __cdecl strtoumax(const char*, char**, int);
intmax_t __cdecl wcstoimax(const __wchar_t*, __wchar_t**, int);
uintmax_t __cdecl wcstoumax(const __wchar_t*, __wchar_t**, int);

#if _INTEGRAL_MAX_BITS == 64
__inline intmax_t strtoimax(const char *__s, char **__endptr, int __radix)
{
	extern __int64 __cdecl _strtoi64(const char*, char**, int);
	return _strtoi64(__s, __endptr, __radix);
}

__inline uintmax_t strtoumax(const char *__s, char **__endptr, int __radix)
{
	extern __int64 __cdecl _strtoui64(const char*, char**, int);
	return _strtoui64(__s, __endptr, __radix);
}

__inline intmax_t wcstoimax(const __wchar_t *__s, __wchar_t **__endptr, int __radix)
{
	extern __int64 __cdecl _wcstoi64(const __wchar_t*, __wchar_t**, int);
	return _wcstoi64(__s, __endptr, __radix);
}

__inline uintmax_t wcstoumax(const __wchar_t *__s, __wchar_t **__endptr, int __radix)
{
	extern __int64 __cdecl _wcstoui64(const __wchar_t*, __wchar_t**, int);
	return _wcstoui64(__s, __endptr, __radix);
}
#endif  /* _INTEGRAL_MAX_BITS == 64 */

#ifdef  __cplusplus
} } }
#endif
